package com.ljx.blog.article.controller;

import com.ljx.blog.article.domain.entity.FriendLink;
import com.ljx.blog.article.domain.vo.req.FriendLinkSubmitReq;
import com.ljx.blog.article.domain.vo.resp.FriendLinkResp;
import com.ljx.blog.article.service.FriendLinkService;
import com.ljx.blog.common.domain.vo.resp.ApiResult;
import com.ljx.blog.security.annotation.ApiPermission;
import com.ljx.blog.security.common.PermissionConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-10-12  22:04
 */
@Api(tags = "友链接口")
@RestController
@RequestMapping("/friendlink")
public class FriendLinkController {

    @Autowired
    private FriendLinkService friendLinkService;

    @ApiOperation("获取友链信息")
    @GetMapping("/info/{id}")
    public ApiResult<FriendLinkResp> getInfo(@PathVariable("id") Long friendLinkId){
        return ApiResult.success(friendLinkService.getInfo(friendLinkId));
    }

    @ApiPermission(permissions = {PermissionConstant.FRIEND_LINK_NEW_EDIT})
    @ApiOperation("保存/更新友链")
    @PostMapping("/submit")
    public ApiResult<FriendLinkResp> submit(@Validated @RequestBody FriendLinkSubmitReq req){
        return ApiResult.success(friendLinkService.submit(req));
    }

    @ApiOperation("获取租户友链列表")
    @GetMapping("/list")
    public ApiResult<List<FriendLinkResp>> getList(){
        return ApiResult.success(friendLinkService.getList());
    }

    @ApiPermission(permissions = {PermissionConstant.FRIEND_LINK_LIST, PermissionConstant.ADMIN_LIST})
    @ApiOperation("获取租户友链列表（管理员）")
    @GetMapping("/admin/list")
    public ApiResult<List<FriendLink>> getListByAdmin(){
        return ApiResult.success(friendLinkService.getListByAdmin());
    }

}
